package com.ihr360.insurance.service.impl;

import com.ihr360.authority.sharing.annonation.AccessControl;
import com.ihr360.commons.lang.DateUtils;
import com.ihr360.event.annonation.RestEventHandler;
import com.ihr360.insurance.dao.MandatoryBenefitsModeReposity;
import com.ihr360.insurance.eventhandler.MandatoryBenefitsModeRestEventListener;
import com.ihr360.insurance.model.dto.benefits.MandatoryBenefitsMode;
import com.ihr360.insurance.service.MandatoryBenefitsModeService;
import com.ihr360.rest.reposity.SimpleRestReposity;
import com.ihr360.rest.service.AbstractSimpleRestServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author Stone.Shi
 * @description
 * @date 2018-01-11 15:39:02.
 */
@Service
@RestEventHandler(MandatoryBenefitsModeRestEventListener.class)
@AccessControl(disableAll = true)
public class MandatoryBenefitsModeServiceImpl extends AbstractSimpleRestServiceImpl<MandatoryBenefitsMode, Long> implements MandatoryBenefitsModeService {

    @Autowired
    private MandatoryBenefitsModeReposity reposity;

    @Override
    public SimpleRestReposity<MandatoryBenefitsMode, Long> getSimpleRestReposity() {
        return reposity;
    }

    @Override
    public boolean isCodeExisted(String code) {
        return reposity.countByCode(code) > 0;
    }

    @Override
    public boolean isNameExisted(String name) {
        return reposity.countByName(name) > 0;
    }

    @Override
    public List<MandatoryBenefitsMode> getCurrentValidModes() {
        Date yearMonthDate = DateUtils.getYearMonthDate(new Date());
        return reposity.getCurrentValidModes(yearMonthDate);
    }
}
